#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "sio.h"
#include "LCD.h"

uint8_t check_Command(char *text)
{
	uint16_t i = 0xA00, j = 80;

	if(strcmp(text, "/clear") == 0)
	{
		CLS_LCD();
		return 1;
	}
	else if(strcmp(text, "/BL_Off") == 0)
	{
		PORTB &= ~_BV(PB0);
		return 1;
	}
	else if(strcmp(text, "/BL_On") == 0)
	{
		PORTB |= _BV(PB0);
		return 1;
	}
	else if(strcmp(text, "/LED_On") == 0)
	{
		PORTC &= ~_BV(PC6) & ~_BV(PC5);
		return 1;
	}
	else if(strcmp(text, "/LED_Off") == 0)
	{
		PORTC |= _BV(PC6) | _BV(PC5);
		return 1;
	}
	else if(strcmp(text, "/LCD_Off") == 0)
	{
		LCD_Display(0);
		return 1;
	}
	else if(strcmp(text, "/LCD_On") == 0)
	{
		LCD_Display(1);
		return 1;
	}
	else if(strcmp(text, "/TheMatrix") == 0)
	{
		while(i > 1)
		{
			LCD_Write(i % 128);
			_delay_ms(1);
			i--;
		}
		CLS_LCD();
		return 1;
	}
	else if(strcmp(text, "/Type_To_LCD") == 0)
	{
		type_To_LCD();
		return 1;
	}
	else if(strcmp(text, "/Smile") == 0)
	{
		while(j > 0)
		{
			LCD_Write(0x0C);
			j--;
		}
		return 1;
	}
	else
	{
		return 0;
	}
	
	//if(strcmp(text, "/Up") == 0)
	//if(strcmp(text, "/Down") == 0)

	//if(strcmp(text, "/RF_Off") == 0)
	//if(strcmp(text, "/RF_On") == 0)
	//if(strcmp(text, "/RF_Channel") == 0)
		// Call Function to take input for the channel number
	//if(strcmp(text, "/RF_Scan") == 0)

	// NEED MOAR AWSUM IDEARS
}

void get_Input(void)
{
	uint8_t i = 0;
	char input_string[81] = "";
	unsigned char input_char = 0;

	while(input_char != 0x0D)
	{
		input_char = inchar();

		if((input_char == 0x08) && (i > 0))
		{
			i--;
			input_string[i] = 0x00;
		}
		else if((input_char != 0x08) && (input_char != 0x0D) && (i < 80))
		{
			input_string[i] = input_char;
			i++;
		}
	}

	if(!check_Command(input_string))
	{
		CLS_LCD();
		print_LCD(input_string, 0, strlen(input_string));
	}
}
